<template>
  <div class="myHome">
    <alertTip v-if="showAlert" @closeTip="go()" :alertText="alertText"></alertTip>
    <loading v-show="showLoading "></loading>
    <alertTip v-if="showAlert" @closeTip="go()" :alertText="alertText"></alertTip>
    <!--<headers title="我的"></headers>-->
    <div class="top">
      <div class="tTop">
        <div class="logo" @click="personal">
          <!--<router-link to="/perInformation">-->
          <img :src="userInfo.headImg" alt="">
          <p>{{userInfo.nickName}}</p>
          <!--</router-link>-->
        </div>
        <router-link to="/Messages" class="xiaoxi">
          <img src="../assets/images/ico_xiaoxi@1x.png" alt="">
          <b v-if="myList.orderCount!==0">{{myList.orderCount}}</b>
        </router-link>
      </div>
    </div>
    <div class="myOrder">
      <mt-cell
        title="我的订单"
        to="/myOrderAll"
        is-link
        value="查看全部">
      </mt-cell>
      <ul>
        <router-link to="/myOrderIng">
          <li>
            <img src="../assets/images/pdzhong@1x.png" alt="">
            <p>拼单中</p>
            <b v-if="myList.orderCount!==0">{{myList.orderCount}}</b>
          </li>
        </router-link>
        <router-link to="/myOrderWaiting">
          <li>
            <img src="../assets/images/daifahuo@1x.png" alt="">
            <p>待发货</p>
            <b v-if="myList.orderWaitCount!==0">{{myList.orderWaitCount}}</b>
          </li>
        </router-link>
        <router-link to="/myOrderAlready">
          <li>
            <img src="../assets/images/yifahuo@1x.png" alt="">
            <p>已发货</p>
            <b v-if="myList.orderAlreadyCount!==0">{{myList.orderAlreadyCount}}</b>
          </li>
        </router-link>
        <router-link to="/myOrderReturn">
          <li>
            <img src="../assets/images/tuikuan@1x.png" alt="">
            <p>退款/售后</p>
            <b v-if="myList.orderRefundCount!==0">{{myList.orderRefundCount}}</b>
          </li>
        </router-link>
      </ul>
    </div>
    <div class="guanli">
      <!--<mt-cell title="我的收藏" to="/Collect" is-link>-->
      <!--<img slot="icon" src="../assets/images/ico_wdsc@1x.png" width="24" height="24">-->
      <!--</mt-cell>-->
      <!--<mt-cell title="我的银行卡" to="/creditCard" is-link>-->
      <!--<img slot="icon" src="../assets/images/ico_wdyhk@1x.png" width="24" height="24">-->
      <!--</mt-cell>-->
      <div @click="goAddress()">
        <mt-cell title="收货地址" is-link>
          <img slot="icon" src="../assets/images/ico_shdz@1x.png" width="24" height="24">
        </mt-cell>
      </div>
      <div @click="goBill()">
        <mt-cell title="发票管理" to="/bill" is-link>
          <img slot="icon" src="../assets/images/ico_fpgl@1x.png" width="24" height="24">
        </mt-cell>
      </div>

    </div>
    <div class="bottom">
      <mt-cell title="我要成为分销商" to="./shopSet" is-link>
        <img slot="icon" src="../assets/images/ico_cwjxs@1x.png" width="24" height="24">
      </mt-cell>
      <mt-cell title="帮助" to="./help" is-link>
        <img slot="icon" src="../assets/images/ico_help@1x.png" width="24" height="24">
      </mt-cell>
    </div>
  </div>
</template>

<script>
  /* eslint-disable semi */
  import wx from 'weixin-js-sdk'
  import { wxHttpTool,wx_config, http_getParam, get_shopQrcoe,wx_share,wx_hideAllMenu } from '../components/httpUtil/httpUtil'
  import {msg_10046} from '../message/msg_10046'
  import {relogin} from "../components/httpUtil/httpUtil";
  export default {
    name: 'myHome',
    data () {
      return {
        userInfo: {},
        myList: {},
        showAlert:false,
        alertText:null,
        showLoading: true, //显示加载动画

//        userInformation: ''
      }
    },
    methods: {
      help () {
        this.alertTip( '普通用户操作流程：扫码关注店铺——“我的”点击个人头像，修改个人信息');
        this.go=function () {
          this.showAlert = false
        }
      },
      // 隐藏动画
      hideLoading(){
        this.showLoading = false;
      },
      alertTip(msg){
        this.showAlert = true;
        this.alertText = msg;
      },
      go(){
        this.showAlert = false
      },
      goAddress(){
        this.$router.push({name:'addressManage'})
      },
      goBill(){
        this.$router.push({name:'bill'})
      },
      getData () {
        const jsonValue = JSON.stringify({
          'c': '10048',
          'p': {
            'userId': JSON.parse(window.localStorage.data).id,
            'tokenId': token()
          }
        })
        this.$http.post(api + '/qqs.us', jsonValue).then((res) => {
          this.hideLoading()
          console.log(res)
          if (res.data.p.isTrue) {
            this.showLoading = false
            this.userInfo = res.data.p.userInfo;
            window.localStorage.data = JSON.stringify(res.data.p.userInfo);
            this.myList = res.data.p;
          }
          else {
            let _this = this
            console.log(_this)
            this.alertTip(res.data.p.errorMsg);
            if (res.data.p.errorCode === 90) {
              this.go= ()=> {
                this.showAlert = false

                relogin(_this)
                // this.$router.push('/fxlogin')
              }
            }

          }
        }, (res) => {

          this.hideLoading();
          this.alertTip('网络错误');
          this.go = function(){
             this.showAlert = false;
          }
          // alert('网络错误');
        })
      },
      personal () {
        window.localStorage.url = this.userInfo.headImg;
        this.$router.push({name: 'perInformation', params: {}})
      }
    },
    created () {
      wxHttpTool.wxAuthor(this, function (varRet, varJson, varThis = this) {
        if (varRet == -1) {
          varThis.alertTip('网络错误');
          varThis.go = function () {
            varThis.showAlert = false;
          }

        }
        // 关注钱应该判断下是否已经关注过了
        msg_10046.send(varThis,msg_10046.entity(),function(varThis,res){
          varThis.wxlist=res.data.p.sign
          wx_config(varThis.wxlist);
          wx_hideAllMenu();
          wx.hideMenuItems({
            //禁用单独分享朋友圈QQ空间等功能
            menuList: ["menuItem:share:timeline","menuItem:share:QZone","menuItem:share:qq"] // 要隐藏的菜单项，所有menu项见附录3
          });
        })


      },this.type)
      window.localStorage.historyUrl = window.location.href;
      if(window.localStorage.data){
        this.getData();
      }
      else {

        this.hideLoading();
        this.alertTip( '请先登录');
        this.go=function () {
          this.showAlert = false
          let _this = this
          relogin(_this)
        }
        // alert("请先登录")
        // this.$router.push("/fxlogin")
      }
//      console.log(this.$route.params.userInfo);
//      if (this.$route.params.userInfo !== undefined) {
//        this.userInformation = this.$route.params.userInfo;
////        console.log('22222222')
//      } else {
//        this.userInformation = JSON.parse(window.localStorage.data)
//      }
    }
  }
</script>

<style scoped>
  .myHome {
    height: 100%;
    background: #f4f4f4;
    padding-bottom: 20px;
  }

  /*头部信息*/
  .myHome .top {
    /*height: 233px;*/
    background: #ffffff;
  }

  .myHome .tTop {
    height: 233px;
    margin-top: -21px;
    background: url("../assets/images/beijing@1x.png") no-repeat;
    background-size: 100% 233px;
    position: relative;
  }

  .myHome .top .logo {
    text-align: center;
  }

  .myHome .top .logo img {
    display: inline-block;
    width: 112px;
    height: 112px;
    margin: 42px 0 10px;
    border-radius: 50%;
    border: 3px solid #ffffff;
  }

  .myHome .top .logo p {
    font-size: 28px;
    color: #ffffff;
  }

  .myHome .top .xiaoxi {
    position: absolute;
    bottom: 140px;
    right: 0px;
  }

  .myHome .top .xiaoxi img {
    width: 40px;
    height: 38px;
    margin: 59px 35px 0 0;
  }

  .myHome .top .xiaoxi b {
    width: 38px;
    height: 24px;
    display: inline-block;
    text-align: center;
    line-height: 24px;
    background: url("../assets/images/bg_xiaoxi@1x.png") no-repeat;
    background-size: 100%;
    color: #fe3519;
    font-size: 20px;
    position: absolute;
    top: 45px;
    right: 10px;
  }

  /*我的订单*/
  .myOrder {
    margin-bottom: 20px;
  }

  .myOrder ul {
    height: 142px;
    text-align: center;
    background: #ffffff;
  }

  .myOrder ul li {
    float: left;
    width: 25%;
    margin-top: 25px;
    position: relative;
  }

  .myOrder ul li p {
    font-size: 20px;
    color: #3b3b43;
  }

  .myOrder ul li img {
    width: 48px;
    height: 45px;
    margin-bottom: 10px;
  }

  .myOrder ul li b {
    display: inline-block;
    width: 30px;
    height: 30px;
    line-height: 30px;
    font-size: 20px;
    color: #ffffff;
    background: url("../assets/images/ico_pindan@1x.png") no-repeat;
    background-size: 100%;
    position: absolute;
    top: -15px;
    right: 25px;
  }

  /*我的收藏、银行卡、地址、发票*/
  .guanli {
    margin-bottom: 20px;
  }
</style>
<style>
  .myHome .mint-cell-title {
    padding-left: 15px;
  }

  .mint-cell-wrapper {
    background-image: none;
  }

  .mint-cell {
    border-bottom: 1px solid #f4f4f4;
  }
</style>
